﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using System.Drawing;

namespace TienLen
{
    /// <summary>
    /// Utility class with miscellaneous and UI methods.
    /// </summary>
    class Util
    {
        #region UI Related

        /// <summary>
        /// API Call - Load a cursor through IntPtr.
        /// </summary>
        /// <param name="filename">The full filepath to the cursor.</param>
        [DllImport("user32.dll")]
        private static extern IntPtr LoadCursorFromFile(string filename);

        /// <summary>
        /// Set a custom cursor for a control.
        /// </summary>
        /// <param name="control">The control you want to set the cursor with.</param>
        /// <param name="curtype">The type of cursor to set.</param>
        static internal void LoadCursor(Control control, CursorType curtype)
        {
            // If the user doesn't want custom cursors, defualt cursors given instead.
            if (TienLen.Properties.Settings.Default.opt_cursor == false)
                switch (curtype)
                {
                    case CursorType.Default: control.Cursor = Cursors.Default; return;
                    case CursorType.Link: control.Cursor = Cursors.Hand; return;
                }

            // Custom cursors
            switch (curtype)
            {
                case CursorType.Default: control.Cursor = new Cursor(LoadCursorFromFile(Application.StartupPath + @"\img\cursors\arrow.ani")); return;
                case CursorType.Link: control.Cursor = new Cursor(LoadCursorFromFile(Application.StartupPath + @"\img\cursors\link.ani")); return;
            }
        }

        /// <summary>
        /// Inverts the given colour.
        /// </summary>
        static internal Color Invert(Color color)
        {
            return Color.FromArgb(255 - color.R, 255 - color.G, 255 - color.B);
        }

        #endregion
    }
}
